#!/bin/sh
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.

. $LKP_SRC/lib/job.sh
load_job_vars GIT_SERVER os

deploy()
{
	# redirect remote-repository address to "/srv/git/gitee.com"
	if [ -n "$GIT_SERVER" ]; then
		cat >> /etc/gitconfig <<-EOF
		[url "git://$GIT_SERVER/gitee.com"]
			insteadOf=https://gitee.com
		EOF
	fi

	mkdir -p /c && cd /c
        git --version #2> /dev/null
        if [ $? -ne 0 ]
        then
                if [ "$os" = "debian" ]
                then
                        apt install -y git
                elif [ "$os" = "centos" ]
                then
                        yum install -y git
                fi
        fi
	git clone https://gitee.com/openeuler/compass-ci.git

	cd /c/compass-ci || exit
	[ -n "$compass_commit_id" ] && git reset --hard "$compass_commit_id"

	# Need mount tmpfs to fix compass-ci/container/os-nfs/start error
	# "exportfs: /exports/result does not support NFS export"
	mount -t tmpfs none /srv

	# test the script for one-click deployment
	cd /c/compass-ci/sparrow || exit
        sed -i '8s/my_account:/my_account: zhaigaoshou/' setup.yaml || exit
        sed -i '9s/my_name:/my_name: zhaigaoshou/' setup.yaml || exit
        sed -i '10s/my_email:/my_email: gszhai@bjtu.edu.cn/' setup.yaml || exit
        sed -i '15s/lab:/lab: z9/' setup.yaml ||exit
	prepare_testboxes=false ./install-tiny
}

deploy
